package top.zhangjianyong.tools.utils;

import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ： zhangjianyong
 * @date ： 2022/11/30 3:28 PM
 */
public class ChronoUnitUtil {
    private final static Map<String, TemporalUnit> map = new HashMap<>();

    public static ChronoUnit getByName(String name) {
        return Arrays.stream(ChronoUnit.values())
                .filter(unit -> unit.name().equalsIgnoreCase(name))
                .findFirst().orElseThrow(() -> new RuntimeException("错误的时间单位"));
    }

}
